package client.gui;

import java.io.*;
import javax.swing.event.*;
import javax.swing.*;
import java.net.*;
import java.awt.event.*;
import java.awt.*;

/**
 * A basic help window, displaying a web page containing the User documentation
 * of the program
 * 
 * @author Da Silva Yvan
 * @author Masson Christian
 * 
 */
class HelpWindow extends JFrame implements ActionListener {

	/**
	 * HelpWindow constructor
	 * 
	 * @param title
	 *            The window title
	 * @param url
	 *            The web page link
	 * @param parent
	 *            The parent window
	 */
	public HelpWindow(String title, URL url, Component parent) {
		super(title);
		editorPane = new JEditorPane();
		editorPane.setEditable(false);
		try {
			editorPane.setPage(url);
		} catch (Exception e) {
		}
		editorPane.addHyperlinkListener(new HyperlinkListener() {
			public void hyperlinkUpdate(HyperlinkEvent event) {
				try {
					if (event.getEventType() == 
						HyperlinkEvent.EventType.ACTIVATED) {
						editorPane.setPage(event.getURL());
					}
				} catch (IOException e) {
				}
			}
		});
		getContentPane().add(new JScrollPane(editorPane));
		JButton btnclose = new JButton("Close");
		btnclose.addActionListener(this);
		JPanel panebuttons = new JPanel();
		panebuttons.add(btnclose);
		getContentPane().add(panebuttons, BorderLayout.SOUTH);
		setSize(parent.getWidth() / 2, parent.getHeight());
		setLocation((int) (parent.getLocation().getX() + parent.getSize()
				.getWidth() / 2), (int) parent.getLocation().getY());
		setVisible(true);
	}

	/**
	 * ActionPerformed read action from user on the window.
	 * 
	 * @param e
	 *            The event performed
	 */
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand() == "Close")
			this.dispose();
	}

	private JEditorPane editorPane;
	private static final long serialVersionUID = 1L;

}